<?php

/**
 * XHTML_Common_Element, xhtml_lib
 * 
 * This file contains the source code for the XHTML_Common_Element class.
 * @author Fernando Jimenez Mocobono <fjmcool@gmail.com>
 * @version 0.1
 * @package xhtml_lib
 */

include_once "XHTML_I18n_Element.php";
include_once "XHTML_Core_Attributes.php";
include_once "XHTML_Event_Attributes.php";

/**
 * The XHTML_Common_Element abstract class implements the common atributes
 * and methods for the most of the xhtml elements as a part of a xhtml-strict
 * php-handler implementation.
 */
abstract class XHTML_Common_Element extends XHTML_I18n_Element implements XHTML_Core_Attributes,
XHTML_Event_Attributes, Echoable {
    
    /**
     * Unique identifier for the id xhtml-core-attribute.
     * 
     * @var string
     */
    protected $id;
    
    /**
     * Class_rule or style_rule for the class xhtml-core-attribute.
     *
     * @var string
     */
    protected $class;
    
    /**
     * Inline style definition for the style xhtml-core-attribute.
     *
     * @var string
     */
    protected $style;
    
    /**
     * Title text for the title xhtml-core-attribute.
     *
     * @var string
     */
    protected $title;
    
    /**
     * Script for the onclick xhtml-event-attribute.
     *
     * @var string
     */
    protected $onClickScript;
    
    /**
     * Script for the ondblclick xhtml-event-attribute.
     *
     * @var string
     */
    protected $onDblClickScript;
    
    /**
     * Script for the onmousedown xhtml-event-attribute.
     *
     * @var string
     */
    protected $onMouseDownScript;
    
    /**
     * Script for the onmouseup xhtml-event-attribute.
     *
     * @var string
     */
    protected $onMouseUpScript;
    
    /**
     * Script for the onmousemove xhtml-event-attribute.
     *
     * @var string
     */
    protected $onMouseMoveScript;
    
    /**
     * Script for the onmouseout xhtml-event-attribute.
     *
     * @var string
     */
    protected $onMouseOutScript;
    
    /**
     * Script for the onkeypress xhtml-event-attribute.
     *
     * @var string
     */
    protected $onKeyPressScript;
    
    /**
     * Script for the onkeydown xhtml-event-attribute.
     *
     * @var string
     */
    protected $onKeyDownScript;
    
    /**
     * Script for the onkeyup xhtml-event-attribute.
     *
     * @var string
     */
    protected $onKeyUpScript;
    

    // Method implementation for the XHTML_Core_Attributes interface.
    
    /**
     * Sets the unique identifier for this element.
     *
     * @param string $id
     */
    function setId($id)
    {
        $this->id = $id;
    }
    
    /**
     * Gets the unique identifier that has been set for this element.
     * 
     * @return string
     */
    function getId()
    {
        return $this->id;
    }
    
    /**
     * Sets the class_rule or style_rule for this element.
     * i.e. The CSS pseudo-class name.
     *
     * @param string $className
     */
    function setClass($class)
    {
        $this->class = $class;
    }
    
    /**
     * Gets the class_rule or style rule that has been set for this element.
     * 
     * @return string;
     */
    function getClass()
    {
        return $this->class;
    }
    
    /**
     * Sets the inline style definition for this element.
     *
     * @param string $style
     */
    function setStyle($style)
    {
        $this->style = $style;
    }
    
    /**
     * Gets the inline style definition that has been set for this element.
     *
     * @return string
     */
    function getStyle()
    {
        return $this->style;
    }
    
    /**
     * Sets the title text for this element.
     *
     * @param string $title
     */
    function setTitle($title)
    {
        $this->title = $title;
    }
    
    /**
     * Gets the title text that has been set for this element.
     *
     * @return string
     */
    function getTitle()
    {
        return $this->getTitle();
    }
    
    
    //Method implementation for the XHTML_Event_Attributes interface.
    
    /**
     * Sets the onclick event script for this element.
     *
     * @param string $script
     */
    function setOnClick($script)
    {
        $this->onClickScript = $script;
    }
    
    /**
     * Gets the onclick event script that has been set for this element.
     * 
     * @return string
     */
    function getOnClick()
    {
        return $this->onClickScript;
    }
    
    /**
     * Sets the ondblclick event script for this element.
     *
     * @param string $script
     */
    function setOnDblClick($script)
    {
        $this->onDblClickScript = $script;
    }
    
    /**
     * Gets the ondblclick event script that has been set for this element.
     *
     * @return string
     */
    function getOnDblClick()
    {
        return $this->onDblClickScript;
    }
    
    /**
     * Sets the onmousedown event script for this element.
     *
     * @param string $script
     */
    function setOnMouseDown($script)
    {
        $this->onMouseDownScript = $script;
    }
    
    /**
     * Gets the onmousedown event script that has been set for this element.
     *
     * @return string
     */
    function getOnMouseDown()
    {
        return $this->onMouseDownScript;
    }
    
    /**
     * Sets the onmouseup event script for this element.
     *
     * @param string $script
     */
    function setOnMouseUp($script)
    {
        $this->onMouseUpScript = $script;
    }
    
    /**
     * Gets the onmouseup event script that has been set for this element.
     *
     * @return string
     */
    function getOnMouseUp()
    {
        return $this->onMouseUpScript;
    }
    
    /**
     * Sets the onmousemove event script for this element.
     *
     * @param string $script
     */
    function setOnMouseMove($script)
    {
        $this->onMouseMoveScript = $script;
    }
    
    /**
     * Gets the onmousemove event script that has been set for this element.
     *
     * @return string
     */
    function getOnMouseMove()
    {
        return $this->onMouseMoveScript;
    }
    
    /**
     * Sets the onmouseout event script for this element.
     *
     * @param string $script
     */
    function setOnMouseOut($script)
    {
        $this->onMouseOutScript = $script;
    }
    
    /**
     * Gets the onmouseout event script that has been set for this element.
     *
     */
    function getOnMouseOut()
    {
        return $this->onMouseOutScript;
    }
    
    /**
     * Sets the onkeypress event script for this element.
     *
     * @param string $script
     */
    function setOnKeyPress($script)
    {
        $this->onKeyPressScript = $script;
    }
    
    /**
     * Gets the onkeypress event script that has been set for this element.
     *
     * @return string
     */
    function getOnKeyPress()
    {
        return $this->onKeyPressScript;
    }
    
    /**
     * Sets the onkeydown event script for this element.
     *
     * @param string $script
     */
    function setOnKeyDown($script)
    {
        $this->onKeyDownScript = $script;
    }
    
    /**
     * Gets the onkeydown event script that has been set for this element.
     *
     * @return string
     */
    function getOnKeyDown()
    {
        return $this->onKeyDownScript;
    }
    
    /**
     * Sets the onkeyup event script for this element.
     *
     * @param string $script
     */
    function setOnKeyUp($script)
    {
        $this->onKeyUpScript = $script;
    }
    
    /**
     * Gets the onkeyup event script that has been set for this element.
     *
     * @return string
     */
    function getOnKeyUp()
    {
        return $this->onKeyUpScript;
    }
    
    
    // Overriding the toString method.
    
    /**
     * Returns the string representation for echoing the class atributes.
     *
     * @return string
     */
    function toString()
    {
        $auxString = parent::toString();
        
        // An attribute is added to the return string only if it is set.
        
        if (isset($this->id)) {
            $auxString = $auxString."id=\"".$this->id."\" ";
        }
        
        if (isset($this->class)) {
            $auxString = $auxString."class=\"".$this->class."\" ";
        }
        
        if (isset($this->style)) {
            $auxString = $auxString."style=\"".$this->style."\" ";
        }
        
        if (isset($this->title)) {
            $auxString = $auxString."title=\"".$this->title."\" ";
        }
        
        if (isset($this->onClickScript)) {
            $auxString = $auxString."onclick=\"".$this->onClickScript."\" ";
        }
        
        if (isset($this->onDblClickScript)) {
            $auxString = $auxString."ondblclick=\"".$this->onDblClickScript
                ."\" ";
        }
        
        if (isset($this->onMouseDownScript)) {
            $auxString = $auxString."onmousedown=\"".$this->onMouseDownScript
                ."\" ";
        }
        
        if (isset($this->onMouseUpScript)) {
            $auxString = $auxString."onmouseup=\"".$this->onMouseUpScript
                ."\" ";
        }
        
        if (isset($this->onMouseMoveScript)) {
            $auxString = $auxString."onmousemove=\"".$this->onMouseMoveScript
                ."\" ";
        }
        
        if (isset($this->onMouseOutScript)) {
            $auxString = $auxString."onmouseout=\"".$this->onMouseOutScript
                ."\" ";
        }
        
        if (isset($this->onKeyPressScript)) {
            $auxString = $auxString."onkeypress=\"".$this->onKeyPressScript
                ."\" ";
        }
        
        if (isset($this->onKeyDownScript)) {
            $auxString = $auxString."onkeydown=\"".$this->onKeyDownScript
                ."\" ";
        }
        
        if (isset($this->onKeyUpScript)) {
            $auxString = $auxString."onkeyup=\"".$this->onKeyUpScript."\" ";
        }
        
        return $auxString;
        
    }
    
}

?>